package com.kun.hosp.service.impl;


import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.digest.HMac;
import cn.hutool.crypto.digest.MD5;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kun.hosp.mapper.HospitalSetMapper;
import com.kun.hosp.service.HospitalSetService;
import com.kun.model.entity.hosp.HospitalSet;
import com.kun.model.vo.hosp.HospitalSetQueryVo;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.Random;


@Service
public class HospitalSetServiceImpl extends ServiceImpl<HospitalSetMapper, HospitalSet> implements HospitalSetService {

    /**
     * 查询
     * @param current
     * @param limit
     * @param param
     * @return
     */
    @Override
    public Page<HospitalSet> findHospitalset(Long current, Long limit, Map<String,Object> param) {
        String hosName = (String) param.get("hosName");
        String hosCode= (String) param.get("hosCode");
        Page<HospitalSet> page=new Page<>(current,limit);
        QueryWrapper<HospitalSet> wrapper = new QueryWrapper<>();
            if(!StrUtil.hasEmpty(hosName))
            {
                wrapper.like("hosname",hosName);
            }
            if (!StrUtil.hasEmpty(hosCode))
            {
                wrapper.eq("hoscode",hosCode);
            }
        return this.page(page,wrapper);
    }

    /**
     * 添加
     * @param hospitalSet
     */
    @Override
    public void saveHospitalset(HospitalSet hospitalSet) {
        hospitalSet.setStatus(1);//状态
        String secure = SecureUtil.md5(String.valueOf(System.currentTimeMillis()+ RandomUtil.randomInt(1000)));//生成签名秘钥
        hospitalSet.setSignKey(secure);
        this.save(hospitalSet);
    }
}
